package com.rpp.factory;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Author rpp
 * @Date 2020/6/25 10:55 下午
 */
public class BeanFactory {

    private static Map<String, Object> map = new HashMap<>();

    static {
        //资源配置文件
        String resourcePath = "applicationContext.xml";
        //解析配置文件，创建bean并放入map容器中
        ClassPathApplicationContext classPathApplicationContext = new ClassPathApplicationContext(resourcePath);
        classPathApplicationContext.build(map);

        //解析配置文件，找出注解配置，创建注解对应的bean并放入map容器中
        AnnotationApplicationContext annotationApplicationContext = new AnnotationApplicationContext(resourcePath);
        annotationApplicationContext.build(map);

    }

    public static Object getBean(String id) {
        return map.get(id);
    }
}
